{include file="common/head"}
</head>
<body >
<!--startprint-->
<div class="container-fluid" style="max-width: 900px;">
    <div class="text-center fs-4 mb-2">{$sys.company_name} 订单明细表</div>
    <div class="row" style="font-size: 1rem;">
        <div class="col">
            <div>客户单号：{$order.order_no}</div>
            <div>订单数量：{$order.qty}</div>
            <div>订单金额：{$sys.currency_symbol}{$sum}</div>
            <div>业务负责人：{$order['sales_name']}</div>
        </div>
        <div class="col ">
            <div>下单人：{$order.contact}</div>
            <div>录单时间：{$order.create_time}</div>
            <div>预交货日期：{$order.delivery_date}</div>
            <div>进仑编号：{$order.in_stock}</div>
        </div>

    </div>

    <table class="table  table-hover table-bordered" >
        <thead class="table-info">
            <th>序号 sn</th>
            <th>产品 Item</th>
            <th>单位 Unit</th>
            <th>价格 Price</th>
            <th>数量 Qty</th>
            <th>小计 Total</th>
            <th>已发货</th>
            <th>待发货</th>
            <th>备注 Memo</th>
        </thead>
        <tbody>
            {foreach $list as $k=>$kv}
            <tr>
                <td>{$k+1}</td>
                <td><div>{$kv['name']}</div></td>
                <td>{$kv['unit']}</td>
                <td>{$sys.currency_symbol}{$kv['price']}</td>
                <td id="{$kv['id']}" qty="{$kv['qty']}">
                    x{$kv['qty']}
                    <button type="button" class="btn btn-sm btn-danger" ><span class="bi-pencil"></span></button>
                    <br/>
                    <input type="number" style="width:90px;display: none;" />
                    <button type="button" class="btn btn-sm btn-yes btn-primary" style="display: none;">确认</button>
                    <button type="button" class="btn btn-sm btn-no btn-secondary" style="display: none;">取消</button>
                </td>
                <td>{$sys.currency_symbol}{$kv['total']}</td>
                <td>{$kv['delivery_qty']}</td>
                <td>{$kv['undelivery_qty']}</td>
                <td>{$kv['memo']}</td>
            </tr>
            {/foreach}

            <tr class="table-info">
                <td colspan="3"></td>
               
                <td>Total</td>
                <td>{$num}</td>
                <td>{$sys.currency_symbol}{$sum}</td>
                <td>{$num_deliv}</td>
                <td>{$num_undeliv}</td>
                <td></td>
            </tr>
        </tbody>
    </table>
    <div class="row ">
        <div class="col">日期：{$date}</div>
        <div class="col">打印：{$uname}</div>
    </div>



</div>
<!--endprint-->
<div class="text-center">
    <button class="btn btn-sm btn-primary" type="button" onclick="printpage();">
        <span class="bi-printer"></span> Print
    </button>
</div>

<div style="height:50px;text-align: center;color:#999"></div>
</body>

<script type="text/javascript">

  $(document).ready(function(){
    $(".btn-danger").on('click',function(){
        $(this).hide();
        $(this).siblings().show();
    })
    $(".btn-no").on('click',function(){
        $(this).parent('td').children().hide();
        $(this).siblings('.btn-danger').show();
    })

    $(".btn-yes").on('click',function(){
        var qty =$(this).parent('td').find('input').val();
        var id = $(this).parent('td').attr('id');

        if(!id || !qty || isNaN(qty)){
            layer.open({'content':'Error!'+id+":"+qty});
            return;
        }

        layer.confirm('确认提交修改吗？', {
            btn: ['Yes', 'No'] //按钮
        }, function () {

            $.post("/index.php/order/order_list_edit", { id: id, qty: qty }, function (res) {
                console.log(res.msg)
                if (res.code) {
                    location.reload();
                } else {
                    layer.open({ 'content': res.msg });
                }

            });

        }, function () {
            layer.msg('取消操作!');
        });
    })


  })

    function printpage(){
      let oldStr = window.document.body.innerHTML; // 获取body的内容
      let start = "<!--startprint-->"; // 开始打印标识, 17个字符
      let end = "<!--endprint-->"; // 结束打印标识
      let newStr = oldStr.substr(oldStr.indexOf(start) + 17); // 截取开始打印标识之后的内容
      newStr = newStr.substring(0, newStr.indexOf(end)); // 截取开始打印标识和结束打印标识之间的内容
      window.document.body.innerHTML = newStr; // 把需要打印的指定内容赋给body
      window.print(); // 调用浏览器的打印功能打印指定区域
      window.document.body.innerHTML = oldStr; // body替换为原来的内容
    }
</script>


</body>
</html>
